package cn.smile.controller.basic;

import cn.smile.bean.dto.basic.ExpenseItemDTO;
import cn.smile.bean.dto.basic.PickerDTO;
import cn.smile.bean.form.basic.item.ItemAddForm;
import cn.smile.bean.form.basic.item.ItemUpdateForm;
import cn.smile.bean.form.basic.item.QueryItemForm;
import cn.smile.business.basic.IExpenseItemService;
import cn.smile.commons.response.MyResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/item")
public class ItemController {

    @Resource
    private IExpenseItemService service;

    @PostMapping(value = "addItem")
    public MyResult<Boolean> addItem(@Valid @RequestBody ItemAddForm form) {
        return MyResult.OK(service.addItem(form));
    }

    @PostMapping(value = "updateItem")
    public MyResult<Boolean> updateItem(@Valid @RequestBody ItemUpdateForm form) {
        return MyResult.OK(service.updateItem(form));
    }

    @GetMapping(value = "getItemMap")
    public MyResult<Map<String, ExpenseItemDTO>> getItemMap(@RequestParam("id") String id) {
        return MyResult.OK(service.getItemMap(id));
    }

    @GetMapping(value = "delItem")
    public MyResult<Boolean> delItem(@RequestParam("id") String id) {
        return MyResult.OK(service.delItem(id));
    }

    @PostMapping(value = "getItemPage")
    public MyResult<IPage<ExpenseItemDTO>> getItemPage(@RequestBody QueryItemForm form) {
        return MyResult.OK(service.getItemPage(form));
    }

    @PostMapping(value = "getItemList")
    public MyResult<List<ExpenseItemDTO>> getItemList(@RequestBody QueryItemForm form) {
        return MyResult.OK(service.getItemList(form));
    }

    @GetMapping(value = "getItemById")
    public MyResult<ExpenseItemDTO> getItemById(@RequestParam("id") String id) {
        return MyResult.OK(service.getItemById(id));
    }

    @GetMapping(value = "getItemPickerList")
    public MyResult<List<PickerDTO>> getItemPickerList(){
        return MyResult.OK(service.getItemPickerList());
    }
}
